#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
@file_name: factorial.py
@date: 2025-07-24 18:07
@author: Falling Snow
@desc: 阶乘案例
"""


def factorial_while(n: int):
    fact = 1
    while 1 <= n:
        fact = fact * n
        n -= 1

    return fact


def factorial_for(n: int):
    fact = 1
    for i in range(1, n + 1, 1):
        fact *= i

    return fact


def factorial_recursion(n: int):
    if n <= 1:
        return 1

    return n * factorial_recursion(n - 1)


import functools
import operator


def factorial_reduce(n: int):
    return functools.reduce(operator.mul, range(1, n + 1))
